package Control;

import java.util.ArrayList;
import java.util.HashMap;

import org.jfree.chart.ChartFactory;
import org.jfree.data.category.DefaultCategoryDataset;

import Entity.MsgPackage;
import Entity.Report;
import GUI.EventsInPeriod;
import GUI.ScreenManager;
import GUI.Statistics;
import GUI.ViewReport;

public class HandelReport {
	
	private Statistics statisticsGui; 
	private MsgPackage reportMsg;
	private Report report = new Report();
	private ViewReport vr;
	
	private EventsInPeriod eventsInPeriodGui;
	/**
	 * Constructor
	 */
	public HandelReport() {
		report = new Report();
		 vr= new ViewReport();
		statisticsGui = new Statistics();
		eventsInPeriodGui= new EventsInPeriod();
		reportMsg = new MsgPackage();
		
	}
	/**
	 * This method set in the report entity field the "from and to" month and year 
	 */
	public void reportSetTime(){
		report.setFromMonth(eventsInPeriodGui.getFromMcomboBox().getSelectedItem().toString());
		report.setFromYear(eventsInPeriodGui.getFromYcomboBox().getSelectedItem().toString());
		report.setToMonth(eventsInPeriodGui.getToMcomboBox().getSelectedItem().toString());
		report.setToYear(eventsInPeriodGui.getToYcomboBox().getSelectedItem().toString());
		
	}
	/**
	 * This method sent a request to server to get the amount of events in the given dates 
	 */
	public void eventsInPeriod(){
	
		reportMsg.setObject(report);
		reportMsg.setOp_code(OP_CODE.GET_EVENT_PER_MONTH);
		ScreenManager.getConnection().accept(reportMsg);
		
		Object o = ScreenManager.getConnection().cclient.getMessage();
		HashMap<String, Integer[]> hm = (HashMap<String, Integer[]>) o;
		vr.eInPeriod(hm);
	}
	/**
	 * This method sent a request to server to get the amount of events in the given dates 
	 */
	public void getHolePerPetiod(){
		System.out.println(report.getFromMonth());
		System.out.println(report.getFromYear());
		System.out.println(report.getToMonth());
		System.out.println(report.getToYear());
		
		reportMsg.setObject(report);
		reportMsg.setOp_code(OP_CODE.GET_HOLES_PER_MONTH);
		ScreenManager.getConnection().accept(reportMsg);
		
		Object o = ScreenManager.getConnection().cclient.getMessage();
		System.out.println("back from sql");
		HashMap<String, ArrayList<Report>> hm = (HashMap<String, ArrayList<Report>>) o;
		vr.holePerPetiod(hm);
	}
	/**
	 * @return the eventsInPeriodGui
	 */
	public EventsInPeriod getEventsInPeriodGui() {
		return eventsInPeriodGui;
	}

	/**
	 * @return the statisticsGui
	 */
	public Statistics getStatisticsGui() {
		return statisticsGui;
	}
}
